// 柴垛热榜
async function getHotList(){
	const res=await axios({
		url:'cdArticle/getArticleList',
		method:'post',
		data:{
			hotFlag: "1",
			pageNo: 1,
			pageSize: 10
		}
	})
	// console.log(res.data.result.list)
	const list=res.data.result.list
	const str=list.map((item,index)=>{
		return `
		<li>
			<span class="index">${index+1}</span>
			<span class="title" data-id=${item.id}>${item.title}</span>
		</li>`
	}).join('')
	document.querySelector('.hotList ul').innerHTML=str
}
getHotList()
//推荐品类
async function getCategory(){
	const res=await axios({
		url:'cdCategory/getTjCategory',
	})
	// console.log(res.data.result)
	const list=res.data.result
	const str=list.map(item=>{
		return `
		<li data-id=${item.id}>
			<img src="${item.ccoverImg}" alt="" title='${item.cname}'>
			<span>${item.cname}</span>
		</li>`
	}).join('')
	document.querySelector('.resCategories ul').innerHTML=str
}
getCategory()
//推荐品牌
async function getBrand(){
	const res=await axios({
		url:'cdCategory/getTjBrand'
	})
	// console.log(res.data.result)
	const list=res.data.result
	const str=list.map(item=>{
		return `
		<li data-id=${item.id}>
			<img src="${item.bcoverImg}" alt="" title='${item.bname}'>
			<span>${item.bname}</span>
		</li>`
	}).join('')
	document.querySelector('.resBrand ul').innerHTML=str
}
getBrand()

//搜索栏placeholder
async function getSerachPlace(){
	const res=await axios({
		url:'cdSearch/list',
		params:{pageNo: 1,pageSize: 1}
	})
	// console.log(res.data.result.records[0].searchContent)
	const title=res.data.result.records[0].searchContent
	document.querySelector('.search input').placeholder=title
}
getSerachPlace()
//传参 要搜索的关键词
document.querySelector('.searchBtn').addEventListener('click',e=>{
	e.preventDefault()
	let key=document.querySelector('.search input').value
	if(key==='') key=document.querySelector('.search input').placeholder
	// console.log(key)
	location.href = `./search.html?keyword=${key}`
})
//传参 柴垛热榜文章id
document.querySelector('.hotList').addEventListener('click',e=>{
	// console.log(e.target)
	if(e.target.tagName==='SPAN'){
		// console.log(e.target.dataset.id)
		const articleId=e.target.dataset.id
		location.href=`./article.html?aId=${articleId}`
	}
	
})
//传参 推荐品类id
document.querySelector('.resCategories ul').addEventListener('click',e=>{
	// console.log(e.target)
	// console.log(e.target.parentNode.dataset.id)
	const categoryId=e.target.parentNode.dataset.id
	location.href=`./resCategory.html?id=${categoryId}`

})

//传参 推荐品牌 id
document.querySelector('.resBrand ul').addEventListener('click',e=>{
	// console.log(e.target)
	// console.log(e.target.parentNode.dataset.id)
	const resBrandId=e.target.parentNode.dataset.id
	location.href=`./resBrand.html?id=${resBrandId}`
})

